# Maintainer: Jonathan White <support@dmapps.us>

_realname=argon2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=20171227
pkgrel=2
pkgdesc="This is the reference implementation of Argon2, the password-hashing function that won the Password Hashing Competition (PHC) (mingw-w64)"
arch=('any')
license=('CC0 and Apache 2.0')
url='https://github.com/P-H-C/phc-winner-argon2'
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/${pkgver}.tar.gz"
        libargon2.pc
        001-mingw-fix-install.patch)
sha256sums=('eaea0172c1f4ee4550d1b6c9ce01aab8d1ab66b4207776aa67991eb5872fdcd8'
            '17061b6f504640cec638d69404879a678e15332a4138673f4a8626ff4efc79a3'
            'f442343a3838956db7f452985a7c64985863c6da2829284f3a628ac095f66d0d')

prepare() {
  cd phc-winner-argon2-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-fix-install.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  cp -rf ${srcdir}/phc-winner-argon2-${pkgver} "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  make CC=${MINGW_PREFIX}/bin/gcc OPTTARGET=none
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make install DESTDIR="${pkgdir}" PREFIX="${MINGW_PREFIX}" OPTTARGET=none

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 ${srcdir}/libargon2.pc "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/libargon2.pc"
  sed -e "s|@MINGW_PREFIX@|${MINGW_PREFIX}|g" \
      -e "s|@UPSTREAM_VER@|${pkgver}|g" \
      -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/libargon2.pc
}
